package jblip.gui.components.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;

import javax.swing.JPanel;
import javax.swing.border.Border;

public abstract class ChannelViewComponent<T> extends JPanel {
  private static final long serialVersionUID = 1L;

  private static final Dimension MIN_SIZE = new Dimension(10, 10);

  protected final T data; 
  
  ChannelViewComponent(final T object) {
    this.data = object;
    setMinimumSize(MIN_SIZE);
    setBorder(ComponentBorder.INSTANCE);
  }

  @Override
  public Border getBorder() {
    return ComponentBorder.INSTANCE;
  }

  @Override
  public Color getBackground() {
    return Color.WHITE;
  }

  @Override
  protected void paintComponent(final Graphics g) {
    super.paintComponent(g);
    final Insets insets = getBorder().getBorderInsets(this);
    final int in_width = getWidth() - (insets.left + insets.right);
    final int in_height = getHeight() - (insets.top + insets.bottom);
    g.setColor(ComponentBorder.COLOR);
    g.fillRect(insets.left, insets.top, in_width, in_height);
  }
}